import os
import xmlrpclib
import SimpleXMLRPCServer
EXPERT_MODE = True
def do_log(str):
    print str
if 1:
    class MIAction:
        def _dispatch(self, method, params):
            global  server_quit
            if method == 'quit':
                #mia.put_operation('quit')
                server_quit = 1
                return 0
            elif method == 'get_results':
                result_list = ['get_results_return']#mia.get_result()
                return  result_list
            elif method == 'probe_step':
                return  2#mia.probe_step()
            if short_operations.__dict__.has_key(method):
                if EXPERT_MODE:
                    dolog('Run short.%s() with %s,\n' % (method, params))
                result = short_operations.__dict__[method](*params)
                if EXPERT_MODE:
                    dolog('    which returns %r\n' % (result,))
                return result
            else: # This is a long operation.
                # Return the operation identifier to the caller.
                if EXPERT_MODE:
                    dolog('Put long.%s() with %s' % (method, params))
                #id = mia.put_operation(xmlrpclib.dumps(params, methodname=method, allow_none = 1))
                id = 123
                if EXPERT_MODE:
                    dolog(', and get id %d.\n' % (id))
                return id

    class ReuseXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
        """Reuse server address for handy test."""
        allow_reuse_address = True

    server = ReuseXMLRPCServer(('127.0.0.1', 325),
                           SimpleXMLRPCServer.SimpleXMLRPCRequestHandler,
                           None)
    server.register_instance(MIAction())
    while 1:
        server.handle_request()
        if server_quit:
            break
    # Block until the action process terminate.

